package com.hyfrogx.modules.manage.controller.course;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hyfrogx.common.param.JSONResult;
import com.hyfrogx.common.utils.QueryExt;
import com.hyfrogx.common.utils.R;
import com.hyfrogx.modules.app.utils.FrogConstant;
import com.hyfrogx.modules.manage.controller.BaseController;
import com.hyfrogx.modules.manage.entity.course.CourseManageRemarkEntity;
import com.hyfrogx.modules.manage.service.course.CourseManageRemarkService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author 罗春杰-技术部
 */
@RestController
@RequestMapping("courseManageRemark")
@Api(value = "CourseManageRemarkController",tags = {"后台-课程评论控制类"})
public class CourseManageRemarkController extends BaseController {

    @Autowired
    CourseManageRemarkService remarkService;
    /**
     * 审核状态
     * @param id
     * @param
     * @return
     */
    @RequestMapping(value="updateStatus",method=RequestMethod.POST)
    @ApiOperation("审核状态")
    public R updateStatus(@RequestParam Integer id){
        try {
            CourseManageRemarkEntity remarkEntity = remarkService.getById(id);
            if(remarkEntity.getStatus().equals(FrogConstant.CourseStatus.UPPER)){
                remarkEntity.setStatus(FrogConstant.CourseStatus.LOWER);
            }else {
                remarkEntity.setStatus(FrogConstant.CourseStatus.UPPER);
            }
            remarkService.updateById(remarkEntity);
            return R.ok();
        } catch (Exception e) {
            return R.error(e.getMessage());
        }
    }



    /**
     * 删除评论
     */
    @RequestMapping(value="deleteRemark",method=RequestMethod.POST)
    @ApiOperation("删除评论")
    public R deleteRemark(Integer id){
        try {
            remarkService.removeById(id);
            return R.ok("删除成功");
        } catch (Exception e) {
            return R.error(e.getMessage());
        }
    }

    /**
     * 推荐
     */
    @RequestMapping(value="updateRemarkIsrecommend",method= RequestMethod.POST)
    @ApiOperation("推荐")
    public R updateRemarkIsrecommend(Integer id){
        try {
            CourseManageRemarkEntity remarkEntity = remarkService.getById(id);
            if(remarkEntity.getIsrecommend().equals(FrogConstant.CourseStatus.UPPER)){
                remarkEntity.setIsrecommend(FrogConstant.CourseStatus.LOWER);
            }else {
                remarkEntity.setIsrecommend(FrogConstant.CourseStatus.UPPER);
            }
            remarkService.updateById(remarkEntity);
            return R.ok("操作成功");
        } catch (Exception e) {
            return R.error(e.getMessage());
        }
    }

    /**
     *
     * 查看评论
     */
    @RequestMapping(value = "selectRemark", method = RequestMethod.POST)
    public R selectRemark(@RequestBody Map map) {
        try {
            Page page = remarkService.ListGetPageRemark(new QueryExt(map));
            return R.ok().put("data",page);
        } catch (Exception e) {
            return R.error(e.getMessage());
        }
    }

}
